package com.mdd.front.controller.yangyangLeadingEnterprise.weifengqi;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.entity.yangyangLeadingEnterprise.TWfqReportAuthorization;
import com.mdd.common.entity.yangyangLeadingEnterprise.TWfqReportIndicatorProcessing;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.util.weifengqi.encryptionPassword.AESUtils;
import com.mdd.front.service.yangyangLeadingEnterprise.ITWfqReportAuthorizationService;
import com.mdd.front.service.yangyangLeadingEnterprise.ITWfqReportIndicatorProcessingService;
import com.mdd.front.validate.yangyangLeadingEnterprise.TAppDicCreateValidate;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/wfq/callback")
@Api(tags = "公共方法")
public class CallbackController {

    @Resource
    ITWfqReportAuthorizationService reportAuthorizationService;

    @Resource
    ITWfqReportIndicatorProcessingService reportIndicatorProcessingService;

    /**
     * 羊羊领企---获取报告---授权结果回调
     * @param request
     * @return
     */
    @NotLogin
    @PostMapping("/authorizeCallback")
    @ResponseBody
    public String authorizeCallback(HttpServletRequest request) {
        TWfqReportAuthorization data = new TWfqReportAuthorization();
        data.setCreateTime(new Date());
        data.setTaxNo(request.getParameter("tax_no"));
        data.setTaxNumber(request.getParameter("tax_number"));
        data.setUrlId(request.getParameter("url_id"));
        data.setMsg(request.getParameter("msg"));

        data.setEntName(request.getParameter("ent_name"));
        data.setCreateDate(request.getParameter("create_date"));
        data.setOrderNo(request.getParameter("orderNo"));
        data.setAuthTaxNo(request.getParameter("auth_tax_no"));
        data.setUserFeedbackState(request.getParameter("user_feedback_state"));
        data.setStaffInfo(request.getParameter("staff_info"));
        data.setExpand(request.getParameter("expand"));
        data.setInterfaceCode(request.getParameter("interfaceCode"));
        data.setSecretKey(request.getParameter("secretKey"));
        data.setType(1);
        reportAuthorizationService.insert(data);
        return JsonReturn.success().toJsonStr();
    }

    /**
     * 羊羊领企---获取报告---指标处理完成回调（报告完成通知）
     * @param request
     * @return
     */
    @NotLogin
    @RequestMapping("/indicatorProcessingCallback")
    @ResponseBody
    public String indicatorProcessingCallback(@RequestBody Map<String,String> param, HttpServletRequest request) {
        TWfqReportIndicatorProcessing data = new TWfqReportIndicatorProcessing();
        data.setCreateTime(new Date());
        data.setTaxNo(param.get("tax_no"));
        data.setTaxNumber(param.get("tax_number"));
        data.setUrlId(param.get("url_id"));
        data.setEntName(param.get("ent_name"));
        data.setCreateDate(param.get("create_date"));
        data.setOrderNo(param.get("orderNo"));
        data.setAuthTaxNo(param.get("auth_tax_no"));
        data.setStaffInfo(param.get("staff_info"));
        data.setExpand(param.get("expand"));
        data.setReport(param.get("report"));
        data.setInterfaceCode(param.get("interfaceCode"));
        data.setSecretKey(param.get("secretKey"));
        data.setType(1);
        reportIndicatorProcessingService.insert(data);
        return JsonReturn.success().toJsonStr();
    }

    /**
     * 羊羊领企---获取企业原始数据---授权结果回调
     * @param request
     * @return
     */
    @NotLogin
    @PostMapping("/basicInformationCallback")
    @ResponseBody
    public String basicInformationCallback(HttpServletRequest request) {
        TWfqReportAuthorization data = new TWfqReportAuthorization();
        data.setCreateTime(new Date());
        data.setTaxNo(request.getParameter("tax_no"));
        data.setTaxNumber(request.getParameter("tax_number"));
        data.setUrlId(request.getParameter("url_id"));
        data.setMsg(request.getParameter("msg"));

        data.setEntName(request.getParameter("ent_name"));
        data.setCreateDate(request.getParameter("create_date"));
        data.setOrderNo(request.getParameter("orderNo"));
        data.setAuthTaxNo(request.getParameter("auth_tax_no"));
        data.setUserFeedbackState(request.getParameter("user_feedback_state"));
        data.setStaffInfo(request.getParameter("staff_info"));
        data.setExpand(request.getParameter("expand"));
        data.setInterfaceCode(request.getParameter("interfaceCode"));
        data.setSecretKey(request.getParameter("secretKey"));
        data.setType(2);
        reportAuthorizationService.insert(data);
        return JsonReturn.success().toJsonStr();
    }

    /**
     * 羊羊领企---获取企业原始数据---采集完成通知
     * @param request
     * @return
     */
    @NotLogin
    @RequestMapping("/basicInformationCollectionCallback")
    @ResponseBody
    public String basicInformationCollectionCallback(@RequestBody Map<String,String> param, HttpServletRequest request) {
        TWfqReportIndicatorProcessing data = new TWfqReportIndicatorProcessing();
        data.setCreateTime(new Date());
        data.setTaxNo(param.get("tax_no"));
        data.setTaxNumber(param.get("tax_number"));
        data.setUrlId(param.get("url_id"));
        data.setEntName(param.get("ent_name"));
        data.setCreateDate(param.get("create_date"));
        data.setOrderNo(param.get("orderNo"));
        data.setAuthTaxNo(param.get("auth_tax_no"));
        data.setStaffInfo(param.get("staff_info"));
        data.setExpand(param.get("expand"));
        data.setReport(param.get("report"));
        data.setInterfaceCode(param.get("interfaceCode"));
        data.setSecretKey(param.get("secretKey"));
        data.setType(2);
        reportIndicatorProcessingService.insert(data);
        return JsonReturn.success().toJsonStr();
    }




    public static void main(String[] args) {
        String message = "T3BlcGWnVW54ZCsWd2R3TC95UXVB dEVVOGZNNDgOUWhLVXVWc3EwZjkywXpksHh6MTVIMCtzNmhRVXl5bWRxTGpZa2lzvnQ1VOpFOTI3RXZWNUUVY09LWXpwa2FpMIBKN1oxRnpmQW1xWGhZahSNFRiTGMzMldwvDBlcidRVTk=";
        try {
            String decrypt = AESUtils.decryptForSys(message);
            System.out.println(decrypt);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }



}
